package uk.co.q3c.deplan.server.unit.dao;

import java.util.List;

import org.testng.annotations.Test;

import uk.co.q3c.deplan.client.domain.resource.BaseCalendar;
import uk.co.q3c.deplan.client.domain.resource.IndividualResource;
import uk.co.q3c.deplan.client.domain.resource.PersistenceReferenceException;
import uk.co.q3c.deplan.client.domain.resource.ResourceGroup;
import uk.co.q3c.deplan.client.domain.resource.ResourcePool;

/**
 * 
 * {@link ResourcePool}
 * 
 * @author DSowerby 28 Mar 2009
 * 
 */
@Test
public class ResourcePoolDao_UT extends LocalDatastoreTestCase {
	ResourcePool pool;
	IndividualResource r1;
	ResourceGroup group;

	@Override
	protected void beforeMethod() throws Exception {
		super.beforeMethod();
	}

	@Override
	protected void afterMethod() throws Exception {
		pool = null;
		super.afterMethod();
	}

	public void doit() throws PersistenceReferenceException {
		pool = new ResourcePool(connection);
		r1 = new IndividualResource(connection);
		r1.setName("r1");
		connection.resourceService()
				.save(r1);
		group = new ResourceGroup(connection);
		group.setName("group");
		group.addResource(r1);
		group.save();
		pool.addResource(r1);
		pool.addResource(group);
		pool.setBaseCalendar(new BaseCalendar(connection));
		connection.resourceService()
				.save(pool);

		connection.closeSession();
		List<ResourcePool> pools = connection.resourceService()
				.findResourcePools();
		pool = pools.get(0);
		r1 = (IndividualResource) pool.getResource("r1");
		group = (ResourceGroup) pool.getResource("group");
		connection.closeSession();
	}

}
